package kylin.controller.doc;

import java.util.List;

import kylin.entity.DocInterfaceMethod;
import kylin.pojo.Notify;
import kylin.service.DocInterfaceMethodService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>Class Name : DocInterfaceMethodController</p>
 * <p>Class Desc : 处理接口文档方法的请求与响应</p>
 * <p>Date : 2015-11-5 下午1:49:55</p>
 * <p>Author : XQL</p>
 */
@Controller
@RequestMapping(value="doc/interface")
public class DocInterfaceMethodController {
	
	@Autowired
	private DocInterfaceMethodService docInterfaceMethodService;

	public DocInterfaceMethodService getDocInterfaceMethodService() {
		return docInterfaceMethodService;
	}

	public void setDocInterfaceMethodService(
			DocInterfaceMethodService docInterfaceMethodService) {
		this.docInterfaceMethodService = docInterfaceMethodService;
	}

	/**
	 * <p>Method Name : saveMethod</p>
	 * <p>Method Desc : 保存接口文档方法及参数</p>
	 * <p>Date : 2015-11-5 下午11:53:36</p>
	 * <p>Author : XQL</p>
	 * @param docMethod
	 * @return
	 */
	@RequestMapping(value="saveMethod",consumes="application/json")
	public @ResponseBody Notify saveMethod(@RequestBody DocInterfaceMethod docMethod){
		docInterfaceMethodService.saveMethodAndParams(docMethod);
		return new Notify(200, "保存成功");
	}
	
	/**
	 * <p>Method Name : giveMethodList</p>
	 * <p>Method Desc : 根据接口文档ID查询所有接口方法</p>
	 * <p>Date : 2015-11-6 上午12:42:14</p>
	 * <p>Author : XQL</p>
	 * @param docInterface_id
	 * @return
	 */
	@RequestMapping(value="giveMethodList")
	public @ResponseBody List<DocInterfaceMethod> giveMethodList(int docInterface_id){
		List<DocInterfaceMethod> list = docInterfaceMethodService.giveMethodList(docInterface_id);
		return list;
	}
	
	/**
	 * <p>Method Name : giveOnlyMethod</p>
	 * <p>Method Desc : 根据接口文档方法ID查询接口方法</p>
	 * <p>Date : 2015-11-6 下午9:40:07</p>
	 * <p>Author : XQL</p>
	 * @param docMethod_id
	 * @return
	 */
	@RequestMapping(value="giveOnlyMethod")
	public @ResponseBody DocInterfaceMethod giveOnlyMethod(int docMethod_id){
		return docInterfaceMethodService.giveById(docMethod_id);
	}
	
	/**
	 * <p>Method Name : giveSearchMethod</p>
	 * <p>Method Desc : 根据接口文档ID和方法名称进行模糊查询[索引方式]</p>
	 * <p>Date : 2015-11-7 上午12:05:51</p>
	 * <p>Author : XQL</p>
	 * @param docInterface_id
	 * @param searchStr
	 * @return
	 */
	@RequestMapping(value="giveSearchMethod")
	public @ResponseBody List<DocInterfaceMethod> giveSearchMethod(int docInterface_id,String searchStr){
		return  docInterfaceMethodService.giveSearchMethod(docInterface_id, searchStr);
	}
}
